package testaux;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Expr {

    public static final int error = 1;
    public static final int IDENT = 2;
    public static final int INTCONST = 3;
    public static final int ADD = 10;
    public static final int MIN = 11;
    public static final int MUL = 12;
    public static final int LPAR = 13;
    public static final int RPAR = 14;
    public static final int ASSIGN = 20;
    public static final int INVOCATION = 21;
    public static final int BLOCK = 22;

    private int type;
    private Object data;
    public List<Expr> children;

    public Expr(int type) {
        this.type = type;
        this.data = null;
        this.children = new ArrayList<Expr>();

    }

    public Expr(int type, Object data) {
        this.type = type;
        this.data = data;
        this.children = new ArrayList<Expr>();
    }

    public Expr(int type, Object data, List<Expr> children) {
        this.type = type;
        this.data = data;
        this.children = new ArrayList<Expr>(children);
    }

    public int getType() {
        return type;
    }

    public Object getData() {
        Arrays.asList(1);
        return data;

    }

    public void addChild(Expr child) {
        children.add(child);
    }

    public int childCount() {
        return children.size();
    }

    public Expr get(int num) {
        return children.get(num);
    }

    public String toString() {
        switch (type) {
            case Sym.ADD:
                return "(ADD " + get(0).toString() + " " + get(1).toString() + ")";
            case Sym.MIN:
                return "(MIN " + get(0).toString() + " " + get(1).toString() + ")";
            case Sym.MUL:
                return "(MUL " + get(0).toString() + " " + get(1).toString() + ")";
            case Sym.INTCONST:
                return "(INT " + ((Integer)data).toString() + ")";
            case Sym.IDENT:
                return "(IDENT  " + (String)data + ")";
            case Sym.INVOCATION:
                return ((Invocation)data).toString();
            default:
                return "xxx";
        }
    }
}
